<template>
  <div class="app-container">
    <!--
      queryParam: 查询参数
      ref: 组件引用
      size: 表格尺寸
      :inline: 行内表单
      v-show: 是否显示
    -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!--
      这是一个查询表单
      clearable: 是否可清空
      @keyup.enter.native: 回车事件
      -->

      <!--姓名查询-->
      <el-form-item label="姓名" prop="interviewee">
        <el-input
          v-model="queryParams.interviewee"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!--岗位查询-->
      <el-form-item label="岗位" prop="pName">
        <el-input
          v-model="queryParams.pName"
          placeholder="请输入岗位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!--面试方式查询-->
      <el-form-item label="面试方式" prop="wId">
        <el-input
          v-model="queryParams.way"
          placeholder="请输入面试方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!--电话查询-->
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!--面试时间查询-->
      <el-form-item label="面试时间" prop="userDate">
        <el-date-picker clearable
          v-model="queryParams.userDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择面试时间">
        </el-date-picker>
      </el-form-item>

      <!--学校查询-->
      <el-form-item label="学校" prop="school">
        <el-input
          v-model="queryParams.school"
          placeholder="请输入学校"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!--
      type: 按钮类型 -- primary: 主要按钮 success: 成功按钮 info: 信息按钮 warning: 警告按钮 danger: 危险按钮 text: 文本按钮
      icon: 图标
      size: 按钮尺寸
      -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- :gutter: 栅格间隔  :span: 栅格占据的列数  v-hasPermission: 权限指令  -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!--新增按钮-->
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:info:add']"
        >新增</el-button>
      </el-col>

      <el-col :span="1.5">
        <!--修改按钮-->
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:info:edit']"
        >修改</el-button>
      </el-col>

      <el-col :span="1.5">
        <!--删除按钮-->
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:info:remove']"
        >删除</el-button>
      </el-col>

      <el-col :span="1.5">
        <!--导出按钮-->
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:info:export']"
        >导出</el-button>
      </el-col>

      <el-col :span="1.5">
        <!--导入按钮-->
        <el-button
          type="info"
          plain
          icon="el-icon-upload"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:info:import']"
        >导入</el-button>
      </el-col>


      <!--  :showSearch.sync: 是否显示查询表单 @queryToggle: 查询表单显示隐藏事件  -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!--
    v-loading: 加载状态
    :data="infoList": 表格数据
    @selection-change="handleSelectionChange": 选择事件
    type: 表格类型
    prop: 列属性
    -->
    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="interviewee" />
      <el-table-column label="岗位" align="center" prop="pName"/>
      <el-table-column label="面试方式" align="center" prop="way" />
      <el-table-column label="身份" align="center" prop="iId" :formatter="iIdFormat"/>
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="面试时间" align="center" prop="userDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.userDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="学校" align="center" prop="school" />
      <!--反馈信息-->
      <el-table-column label="反馈信息" align="center" prop="feedback" />
      <!--操作-->
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            v-hasPermi="['system:info:query']"
            @click="selectall(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--
    v-show: 是否显示
    :total: 总条数
    :page.sync: 当前页
    :limit.sync: 每页条数
    @pagination: 分页事件
    -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <!--新增窗口-->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="姓名" prop="interviewee">
          <el-input v-model="form.interviewee" placeholder="请输入姓名"/>
        </el-form-item>

        <el-form-item label="岗位" prop="pName">
          <el-select v-model="form.pName" placeholder="请选择岗位">
            <el-option
              v-for="item in pNameList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="面试方式" prop="way">
          <el-select v-model="form.way" placeholder="请选择">
            <el-option
              v-for="item in wayList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="身份" prop="iId">
          <el-select v-model="form.iId" placeholder="请选择">
            <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择">
            <el-option
              v-for="item in statussome"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>


        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>

        <el-form-item label="面试时间" prop="userDate">
          <el-date-picker clearable
            v-model="form.userDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择面试时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="学校" prop="school">
          <el-input v-model="form.school" placeholder="请输入学校" />
        </el-form-item>

        <!--新增一个反馈窗口-->
        <el-form-item label="反馈" prop="feedback">
          <el-input v-model="form.feedback" placeholder="请输入反馈" />
        </el-form-item>



      </el-form>

      <!--
      slot="footer": 底部内容
      -->
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



    <!--详情窗口-->
    <el-dialog :title="xqtitle" :visible.sync="weeopen" width="500px" append-to-body>
      <el-form ref="xiangqing" label-width="80px">
        <label>
          <span>创建时间：</span>
          <span>{{ this.all.createTime }}</span>
        </label>
        <br>
        <label>
          <span>更新时间：</span>
          <span>{{ this.all.updateTime }}</span>
        </label>
        <br>
        <label>
          <span>姓名：</span>
          <span>{{ this.all.interviewee }}</span>
        </label>
        <br>
        <label>
          <span>岗位：</span>
          <span>{{ this.all.pName }}</span>
        </label>
        <br>
        <label>
          <span>身份：</span>
          <span>{{ this.all.iId }}</span>
        </label>
        <br>
        <label>
          <span>状态：</span>
          <span>{{ this.all.status }}</span>
        </label>
        <br>
        <label>
          <span>电话：</span>
          <span>{{ this.all.phone }}</span>
        </label>
        <br>
        <label>
          <span>面试时间：</span>
          <span>{{ this.all.userDate }}</span>
        </label>
        <br>
        <label>
          <span>学校：</span>
          <span>{{ this.all.school }}</span>
        </label>
        <br>
        <label>
          <span>面试方式：</span>
          <span>{{ this.all.way }}</span>
        </label>
        <br>
        <lablel>
          <span>创建人：</span>
          <span>{{ this.all.createBy }}</span>
        </lablel>
        <br>
        <lablel>
          <span>修改人：</span>
          <span>{{ this.all.updateBy }}</span>
        </lablel>
        <br>
        <label>
          <span>反馈：</span>
          <span>{{ this.all.feedback }}</span>
        </label>


      </el-form>
    </el-dialog>





    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>



  </div>
</template>

<script>
import {listInfo, getInfo, delInfo, addInfo, updateInfo, listInterviewee, listPostinv} from "@/api/system/info";
import {listWay} from "@/api/system/way";
import {getToken} from "@/utils/auth";
import {importTemplate} from "@/api/system/user";


export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      xqtitle: "",
      // 是否显示弹出层
      open: false,
      weeopen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        interviewee: null,
        pId: null,
        wId: null,
        iId: null,
        status: null,
        phone: null,
        userDate: null,
        path: null,
        school: null,
        pName: null,
        way: null,
        feedback: null
      },
      // 表单参数
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        interviewee:[
          { required: true, message: "请输入姓名", trigger: "blur" }
        ],
        phone:[
          { required: true, message: "请输入电话", trigger: "blur" },
          { min: 11, max: 11, message: "长度为11个字符", trigger: "blur" }
        ],
        userDate:[
          { required: true, message: "请选择面试时间", trigger: "blur" }
        ]
      },
      //选中状态
      options: [{
        value: 0,
        label: '未选择'
      }, {
        value: 1,
        label: '校招'
      }, {
        value: 2,
        label: '社招'
      }],
      statussome:[{
        value: 0,
        label: '通过'
      }, {
        value: 1,
        label: '进行中'
      }, {
        value: 2,
        label: '未通过'
      }, {
        value: 3,
        label: '未处理'
      }],
      /* 行数据 */
      row:{},
      /* 所有面试方式 */
      wayList:[],
      /* 所有岗位 */
      pNameList:[],
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/interview/info/importData"
      },
      intervieweemsg: null,
      all:{
        createBy: null,
        createTime: null,
        feedback: null,
        iId: null,
        id: null,
        interviewee: null,
        pName: null,
        phone: null,
        remark: null,
        school: null,
        searchValue: null,
        status: null,
        updateBy: null,
        updateTime: null,
        userDate: null,
        way: null,
      }
    };
  },
  /* 页面加载时执行 */
  created() {
    this.getList();
    this.selectway();
    this.selectpName();
  },
  methods: {

    selectall(row){
      /** 获取当前id  */
      const id = row.id || this.ids
      console.log(id)
      getInfo(id).then(response => {
        this.all = response.data
        console.log(this.all)
        if(this.all.iId == 0){
          this.all.iId = "未选择"
        }else if(this.all.iId == 1) {
          this.all.iId = "校招"
        }else if(this.all.iId == 2) {
          this.all.iId = "社招"
        }else if(this.all.status == 0) {
          this.all.status = "通过"
        }else if(this.all.status == 1) {
          this.all.status = "进行中"
        }else if(this.all.status == 2) {
          this.all.status = "未通过"
        }else if(this.all.status == 3) {
          this.all.status = "未处理"
        }

        this.weeopen = true
        this.xqtitle = "详情信息"
      });



    },


    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },

    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },

    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },


    /** 查询【请填写功能名称】列表 */
    getList() {
      // 加载遮罩
      this.loading = true;
      //查询参数，请求成功，把请求出的行数据赋值给infoList，条数赋值给total
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        interviewee: null,
        pId: null,
        wId: null,
        iId: null,
        status: null,
        phone: null,
        userDate: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
        delFlag: null,
        path: null,
        school: null,
        way: null,
        feedback: null
      };
      /** 重置表单 */
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      /** 重置页码 */
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 多选框选中数据  */
    handleSelectionChange(selection) {
      /** 获取选中的id  非单个禁用  非多个禁用 */
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加面试信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      /** 获取选中的id */
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm() {
      /** 校验表单  */
      this.$refs["form"].validate(valid => {
        /** 如果校验成功  */
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              /** 提示修改成功  */
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            listInterviewee(this.form.interviewee).then(response => {
              if (response.msg == "姓名重复，生成乱码后缀") {
                /** 弹出确认消息框  */
                this.$confirm("姓名重复，生成乱码后缀", "提示", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
                })
                  .then(() => {
                    addInfo(this.form).then(response => {
                      /** 提示新增成功  */
                      this.$modal.msgSuccess("新增成功");
                      this.open = false;
                      this.getList();
                    });
                    /** 点击确定按钮  */
                    this.$message({
                      type: "success",
                      message: "已生成乱码后缀"
                    });
                  })
                  .catch(() => {
                    /** 点击取消按钮  */
                    this.$message({
                      type: "info",
                      message: "已取消"
                    });
                  });
              }
            });


          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      /** 获取选中id  */
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除面试信息编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      /** 导出接口 导出文件名 */
      this.download('interview/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    },
    /** 状态格式化  */
    statusFormat(row){
      if(row.status === 0){
        return '通过'
      }else if(row.status === 1){
        return '进行中'
      }else if(row.status === 2){
        return '未通过'
      }else if(row.status === 3){
        return '未处理'
      }
    },
    /** 状态格式化  */
    iIdFormat(row){
      if(row.iId === 0){
        return '未选择'
      }else if(row.iId === 1){
        return '校招'
      }else if(row.iId === 2){
        return '社招'
      }
    },
    /** 这个方法是获取 “面试” 方式 遍历给wayList  */
    selectway(rows){
      listWay(rows).then(response => {
        for (let i = 0; i < response.rows.length; i++) {
          this.wayList.push({value:response.rows[i].way,label:response.rows[i].way})
        }
      });
    },
    /** 这个方法是获取 “岗位” 方式 遍历给pNameList  */
    selectpName(rows){


        listPostinv(rows).then(response => {
          for (let i = 0; i < response.rows.length; i++) {
            this.pNameList.push({value:response.rows[i].pName,label:response.rows[i].pName})
          }
        }).catch(err =>{

        });



    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then(response => {
        this.download(response.msg);
      });
    }

  }
};
</script>
